package com.hlee.perf;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;

public class JAMonTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {

		//System.setOut(new PrintStream("C:/test.txt"));
		List messages = new ArrayList();
		StringBuffer buf = new StringBuffer();
		
		Monitor mainMon = MonitorFactory.start("main");
		
		Monitor mon = null;
		mon = MonitorFactory.start("m1");
		m1();
		mon.stop();
		messages.add("JAMon label: " + mon.getLabel() + ", time: " + mon.getLastValue());
		buf.append("JAMon label: " + mon.getLabel() + ", time: " + mon.getLastValue() + "\n");
		System.out.println(mon);
		
		for (int i=0; i < 10; i++) {
//			if (i == 5)
//				changeOut();
			
			mon = MonitorFactory.start("m2");
			m2();
			mon.stop();
			messages.add("JAMon label: " + mon.getLabel() + ", time: " + mon.getLastValue());
			buf.append("JAMon label: " + mon.getLabel() + ", time: " + mon.getLastValue() + "\n");
			System.out.println(mon);
		}
		
		mainMon.stop();
		
		for (Iterator iter = messages.iterator(); iter.hasNext(); )
			System.out.println((String) iter.next());
		
		System.out.println(mainMon);
		
		
	}
	
	private static void m1() throws Exception {
		Thread.sleep(500);
	}
	
	private static void m2() throws Exception {
		Thread.sleep(100);
	}
	
	private static void changeOut() throws Exception {
		System.setOut(new PrintStream("C:/test.txt"));
	}

}
